package com.xiaozhengkeji.minecraft.plugin.fishplus.commands;

import com.xiaozhengkeji.minecraft.plugin.fishplus.FishPlus;
import com.xiaozhengkeji.minecraft.plugin.fishplus.utils.FishCoreUtils;
import com.xiaozhengkeji.minecraft.plugin.fishplus.utils.MsgUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Fish;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

/**
 * 管理员命令行
 */
public class AdministratorCommand implements CommandExecutor {
    /*命令触发*/
    @Override
    public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
        if (!(commandSender instanceof Player)) {
            MsgUtils.logServer("请在客户端使用!");
            return true;
        }
        Player p = (Player) commandSender;
        if (!p.isOp()) {
            MsgUtils.logPlayer(p, "无管理员权限!禁止执行!");
            return true;
        }
        if (strings.length == 0) {
            MsgUtils.logPlayer(p, "FishPlus Plugin Help");
            MsgUtils.logPlayer(p, "§a重置配置文件");
            MsgUtils.logPlayer(p, "§e/§1fpa reload");
            MsgUtils.logPlayer(p, "§a将手持物品添加到奖池中(添加完成后可去yml下配置)");
            MsgUtils.logPlayer(p, "§e/§1fpa prize add §e[§4奖品名§e]");
            return true;
        }
        if (strings[0].equalsIgnoreCase("reload")) {
            FishPlus.Main.configRead();
            MsgUtils.logPlayer(p, "§e重载配置文件完成!");
            return true;
        }
        if (strings[0].equalsIgnoreCase("prize")) {
            if (strings[1].equalsIgnoreCase("add")) {
                ItemStack itemStack = p.getInventory().getItemInMainHand();
                if (itemStack != null) {
                    if (strings[2] != null) {
                        if (FishCoreUtils.saveItemPrize(itemStack, strings[2])) {
                            MsgUtils.logPlayer(p, "添加完成! 请去FishPrizeConfig.yml下进行详细配置");
                        } else {
                            MsgUtils.logPlayer(p, "§4添加失败! 具体查看后台!");
                        }
                    } else {
                        MsgUtils.logPlayer(p, "§4请输入奖品名!");
                    }
                } else {
                    MsgUtils.logPlayer(p, "§4请手持物品输入!");
                }
                return true;
            }
        }
        return false;
    }
}
